package com.minutes.in.seconds.emailprovider;

import java.util.regex.Pattern;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.util.Patterns;

public class PrimaryEmailProvider {
	
	public static String getPrimaryEmailAddress(Context context) {
		Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
		Account[] accounts = AccountManager.get(context).getAccounts();
		String email = null;
		for (Account account : accounts) {
		    if (emailPattern.matcher(account.name).matches()) {
		        email = account.name;
		        break;
		    }
		}
		
		return email;
	}
}
